package com.hzqy.web.ac;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hzqy.commons.utils.ConstantUtils;
import com.hzqy.service.publicize.PublicizeServiceBean;
import com.hzqy.web.vo.CmContentVo;
import com.hzqy.web.vo.CmUserOrgVo;
import com.hzqy.web.vo.PmsOrgVo;
import com.hzqy.web.vo.PmsUserVo;
import com.hzqy.web.vo.content.CmContentLedgerVo;

@Controller
@RequestMapping("/publicize")
public class PublicizeAction {
	protected final Logger LOG=LoggerFactory.getLogger(getClass()); 
	
	@Resource
	private PublicizeServiceBean publicizeServiceBean;
	
	/**
	 * 查询广告投放列表
	 */
	@RequestMapping("/user_org_list")
	@ResponseBody
	public Object userOrgList(CmUserOrgVo cmUserOrgVo,int page, int rows){
		Map<String,Object> map = new HashMap<String, Object>();
		map = publicizeServiceBean.selectUserOrgList(cmUserOrgVo,page,rows);
		return map;
	}
	
	/**
	 * 插入广告投放
	 */
	@RequestMapping("/insert_user_org")
	@ResponseBody
	public Object insertUserOrg(CmUserOrgVo cmUserOrgVo, HttpSession session) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		int flag = publicizeServiceBean.insertUserOrg(cmUserOrgVo);
		if(flag>0) {
			resultMap.put("success", true);
			resultMap.put("result","新增成功!");
		} else {
			resultMap.put("success", false);
			resultMap.put("result","新增失败!");
		}
		return resultMap;
	}
	
	/**
	 * 删除广告投放
	 */
	@RequestMapping("/delete_user_org")
	@ResponseBody
	public Object deleteUserOrg(int f_cuo_id, HttpSession session) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		int flag = publicizeServiceBean.deleteUserOrg(f_cuo_id);
		resultMap.put("resultTitle", "删除结果");
		if(flag>0) {
			resultMap.put("success", true);
			resultMap.put("result","删除成功!");
		} else {
			resultMap.put("success", false);
			resultMap.put("result","删除失败!");
		}
		return resultMap;
	}
	
	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@RequestMapping("/batch_delete_user_org")
	@ResponseBody
	public Object batchDeleteUserOrg(String ids) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		int flag = publicizeServiceBean.batchDeleteUserOrg(ids);
		if(flag>0) {
			resultMap.put("success", true);
			resultMap.put("result","批量删除成功!");
		} else {
			resultMap.put("success", false);
			resultMap.put("result","批量删除失败!flag="+flag);
		}
		return resultMap;
	}

	/**
	 * 根据所选条件自动投放
	 */
	@RequestMapping("/batch_contribute")
	@ResponseBody
	public Object batchContribute(CmUserOrgVo cmUserOrgVo,int type) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		resultMap = publicizeServiceBean.batchContribute(cmUserOrgVo,type);
		return resultMap;
	}
	
	/**
	 * 根据所选商户查询可投放的酒店列表
	 */
	@RequestMapping("/select_contribute_org_list")
	@ResponseBody
	public Object selectContributeOrgList(CmUserOrgVo cmUserOrgVo, int page, int rows) {
		Map<String,Object> map = publicizeServiceBean.selectContributeOrgList(cmUserOrgVo, page, rows);
		return map;
	}
	
	/**
	 * 根据所选商户自动投放至目标酒店下的账号
	 */
	@RequestMapping("/batch_contribute_by_org")
	@ResponseBody
	public Object batchContributeByOrg(CmUserOrgVo cmUserOrgVo) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		resultMap = publicizeServiceBean.batchContributeByOrg(cmUserOrgVo);
		return resultMap;
	}
	
	/**
	 * 根据经纬度查询附近几公里内的酒店
	 */
	@RequestMapping("/select_org_by_coordinate")
	@ResponseBody
	public Object selectOrgByCoordinate(double f_po_lon,double f_po_lat, int distance) {
		List<PmsOrgVo> list = publicizeServiceBean.selectOrgByCoordinate(f_po_lon,f_po_lat,distance);
		return list;
	}
	
	/**
	 * 根据酒店orgids查询商户已投放多少酒店
	 */
	@RequestMapping("/select_org_by_orgids")
	@ResponseBody
	public Object selectOrgByOrgids(CmUserOrgVo cmUserOrgVo,String orgids) {
		List<CmUserOrgVo> list = publicizeServiceBean.selectOrgByOrgids(cmUserOrgVo,orgids);
		return list;
	}
}
